package com.ipzoe.web.controller;

import com.ipzoe.common.core.controller.BaseController;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.support.RequestContextUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.Locale;

public class WebBaseController extends BaseController {

    /**
     * 根据语言选择页面
     * @param html
     * @return
     */
    public String getLocaleHtml(String html, HttpServletRequest request){
        LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
        if (localeResolver == null) {
            throw new IllegalStateException(
                    "No LocaleResolver found: not in a DispatcherServlet request?");
        }
        if(localeResolver.resolveLocale(request).equals(Locale.TRADITIONAL_CHINESE)){
            return html.replace(".html", "") + "_zh_TW.html";
        }else{
            return html;
        }
    }
}
